package com.ejlchina.tool.util

import android.app.Activity
import android.graphics.Insets
import android.os.Build
import android.util.Log
import android.view.WindowInsets

fun Activity.getScreenWidthHeight(): Pair<Int,Int>{
    var width: Int
    var height: Int
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.R) {
//            获取的是实际显示区域指定包含系统装饰的内容的显示部分
        width = windowManager.currentWindowMetrics.bounds.width()
        height = windowManager.currentWindowMetrics.bounds.height()
        Log.i(LOG_TAG, "width: $width,height:$height") //720,1491
    } else {
        //获取减去系统栏的屏幕的高度和宽度
        val displayMetrics = resources.displayMetrics
        width = displayMetrics.widthPixels
        height = displayMetrics.heightPixels
        Log.i(LOG_TAG, "width: $width,height:$height") //720,1491
    }
    return Pair(width,height)
}